package cn.ikun.dhj.jdbc;

import java.sql.*;

public class AppJdbcSelect {
    public static void main(String[] args) throws Exception{
        //1加载驱动类
//        String url ="jdbc:mysql://localhost:3306/shixi";
        String url ="jdbc:mysql://localhost:3306/shixi?useSSL=false";
        String username = "root";
        String password ="root";
        Class.forName("com.mysql.jdbc.Driver");
        //2获取数据库连接
        Connection connection = DriverManager.getConnection(url, username, password);
        String sql01 ="select id,username,password from `user` order by id asc ";
        //3创建存数据的对象
        Statement statement = connection.createStatement();
        //4执行查询
        ResultSet set = statement.executeQuery(sql01);
        //5获取数据
        while(set.next()){
            int id = set.getInt(1);
            System.out.print("id="+id+ "  ");
            String uname = set.getString(2);
            System.out.print("username="+uname+"  ");
            String pword = set.getString(3);
            System.out.println("password="+pword+"  ");
        }
//        1    dhj   202cb962ac59075b964b07152d234b70
//        2   gkc   76b90749b2a1fc29edf8d43b58502294
//        3   mzw   d00d69aa0e90866bb2851f176cda07b6

    }
}
